//
//  DM_SQLInsertBuilder.swift
//  构建者模式_ORM_SWIFT
//
//  Created by macOS on 2017/4/22.
//  Copyright © 2017年 macOS. All rights reserved.
//

import UIKit

class DM_SQLInsertBuilder: DM_SQLBuilder {
   
    
    func insert() -> DM_SQLInsertBuilder {
        
        sql.append("insert ")
        return self
        
    }
    
    func into() -> DM_SQLInsertBuilder {
        sql.append("into ")
        return self
    }
    
    override func talbe(_ table: String) -> DM_SQLInsertBuilder {
        return super.talbe(table) as! DM_SQLInsertBuilder
        
    }
    
    override func colums(_ colums: Array<String>) -> DM_SQLInsertBuilder {
        
        sql.append("(")
        
        let builder = super.colums(colums) as! DM_SQLInsertBuilder
        sql.append(") ")
        return builder
    }
    
    
    func keyword_values() -> DM_SQLInsertBuilder {
        sql.append("values ")
        return self
     
    }
    
    //单行
    override func wsj_values(_ values: Array<Any>) -> DM_SQLInsertBuilder {
        
        var builder = keyword_values()
        sql.append("(")
        builder =  super.wsj_values(values) as! DM_SQLInsertBuilder
        sql.append(") ")
        return builder
    }
    //批量插入
    
    func wsj_batckValues(_ values: Array<Array<Any>>) -> DM_SQLInsertBuilder {
        
        
        var builder = keyword_values()
        
        var index = 0
        for value in values {
            index+=1
            sql.append("(")
            builder =  super.wsj_values(value) as! DM_SQLInsertBuilder
            sql.append(") ")
            if index < values.count {
                sql.append(",")
            }
        }
        
        return builder
    }
    
    
    
    
}
